package com.neiquan.backstage.region.test;

import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.io.IOUtils;

public class RegionUtils {

	public static List<String> readLines(String file) throws IOException {
		FileReader fileReader = new FileReader(file);
		try {
			return IOUtils.readLines(fileReader);
		} finally {
			IOUtils.closeQuietly(fileReader);
		}
	}

	public static List<Region> parseAllRegion(List<String> lines) {
		List<Region> list = new ArrayList<>();
		for (String string : lines) {
			String[] split = string.split("\\s+");
			list.add(new Region(split[0], split[1]));
		}
		return list;
	}

	public static List<Region> getAllProvince(List<Region> regions) {
		List<Region> list = new ArrayList<>();
		for (Region region : regions) {
			if (region.getCode().endsWith("0000")) {
				list.add(region);
			}
		}
		return list;
	}

	public static class Region {
		private String code;
		private String name;

		public Region() {
		}

		public Region(String code, String name) {
			this.code = code;
			this.name = name;
		}

		public String getCode() {
			return code;
		}

		public void setCode(String code) {
			this.code = code;
		}

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}
	}
}
